#include <fstream>
#include <string>
#include <iostream>
using namespace std;

void stTag(string title, string css)
{
     ofstream out;
     out.open("log.html");
     out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" << endl;
     out << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" << endl;
     out << "<html>" << endl;
     out << "<head>" << endl;
     out << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << css << "\" />" << endl;
     out << "\t<title>" << title << "</title>" << endl;
     out << "</head>" << endl;
     out << "<body>" << endl;
     out.close();
}

void makeCss(string filename)
{
     ofstream css;
     css.open(filename.c_str(),ios::app);
     css.close();
}

void addCss(string filename, string data)
{
     ofstream css;
     css.open(filename.c_str(),ios::app);
     css << data << endl;
     css.close();
}


void tableAdd(int border, int width, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<table" << " width=\"" << width << "\" border=\"" << border << "\" style=\"" 
         << style << "\" id=\"" << id << "\" " << other << ">" << endl;
     out.close();
}

void tableClose()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t</table>"<< endl;
     out.close();
}

void rowAdd()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t\t<tr>" << endl;
     out.close();
}

void rowClose()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t\t</tr>" << endl;
     out.close();
}

void tdAdd(string data,int width,int colspan,int rowspan,string style,string id,string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t\t\t<td " << " width=\"" << width << "\"" << " colspan=" << colspan 
     << " rowspan=" << rowspan
     << " style=\"" << style << "\" id=\"" << id << "\" " << other << ">";
     out << data;
     out << "</td>" << endl;
     out.close();
}

void brAdd()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<br />" << endl;
     out.close();
}

void hrAdd()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<hr />" << endl;
     out.close();
}

void hAdd(int type, string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<h" << type << " style=\"" << style << "\" id=\"" << id << "\" " 
     << other << ">" << data << "</h" << type << ">" << endl;
     out.close();
}

void pAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<p " << "id=\"" << id  << "\" style=\"" << style << "\" " << other 
     << ">" << data << "</p>" << endl;
     out.close();
}

void scriptAdd(string type)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<script type=\"" << type << "\">" << endl;
     out.close();
}

void script(string scr)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t\t" << scr << endl;
     out.close();
}

void scriptClose()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t</script>" << endl;
     out.close();
}

void emAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<em style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</em>"
     << endl;
     out.close();
}

void strongAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<strong style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</strong>"
     << endl;
     out.close();
}

void dfnAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<dfn style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</dfn>"
     << endl;
     out.close();
}

void codeAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<code style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</code>"
     << endl;
     out.close();
}

void varAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<var style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</var>"
     << endl;
     out.close();
}

void citeAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<cite style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</cite>"
     << endl;
     out.close();
}

void ulAdd(string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<ul style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << endl;
     out.close();
}

void liAdd(string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t\t<li style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << ">" << data << "</li>"
     << endl;
     out.close();
}

void ulClose()
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t</ul>" << endl;
     out.close();
}


void linkAdd(string url, string target, string data, string style, string id, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<a href=\"" << url << "\" style=\"" << style << "\" " <<  
     "id=\"" << id << "\" " << other << " target=\"" << target << "\"" << ">" 
     << data << "</a>" << endl;
     out.close();
}

void anchorAdd(string name)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<a name=\"" << name << "\">" << "</a>" << endl;
     out.close();
}

void gotoAnchor(string name, string data, string style, string other)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t<a href=\"#" << name << "\" style=\"" << style << "\" " << other 
     << ">" << data << "</a>" << endl;
     out.close();
}

void htmlAdd(string data)
{
     ofstream out;
     out.open("log.html",ios::app);
     out << "\t" << data;
     out.close();
}

void rmTag()
{
     string line;
    // open input file
    ifstream in("log.html",ios::in);
    if( !in.is_open())
    {
          cout << "Input file failed to open\n";
          exit(1);
    }
    // now open temp output file
    ofstream out("outfile.txt");
    // loop to read/write the file.  Note that you need to add code here to check
    // if you want to write the line
    while( getline(in,line) )
    {
         if(line != "</body>" && line != "</html>")
         out << line << "\n";
    }
    in.close();
    out.close();    
    // delete the original file
    remove("log.html");
    // rename old to new
    rename("outfile.txt","log.html");
}

void addTag()
{
    ofstream out;
    out.open("log.html",ios::app);
    out << "</body>" << endl;
    out << "</html>" << endl;
    out.close();
}
